package com.example.concurrent;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;

/**
 * @NAME: WSC
 * @DATE: 2021/11/29
 * @DESCRIBE:
 **/
public class TNIO {
    public static void main(String[] args) throws IOException {
        var start = System.nanoTime();
        String path = "hello.txt";
        var file = new RandomAccessFile(path, "rw");
        var channel = file.getChannel();
        var buf = ByteBuffer.allocateDirect(1024);

        while (channel.read(buf) != -1) {

            var s = new String(buf.array());
            System.out.println(s);
            buf.flip();
            buf.clear();
        }


        System.out.println(System.nanoTime() - start);
    }
}
